package com.st.service;

import com.st.mapper.TestMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


@Service
public class TestService {
    @Autowired
    private TestMapper testMapper;

    /**
     * 用于程序是分布式部署的，在这个方法上面加synchronized是无效的，因为这把锁不是全局的
     *
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public int updateNum() {
        int num = testMapper.getNum();
        num++;
        testMapper.updateNum(num);
        return num;
    }
}
